package agent;

import settings.Settings;
import driver.Move;
import driver.SystemDriver;
import environment.Environment;

public class Agent implements Runnable {
	
	int side, cellCount, ID, currentX, currentY, nextX, nextY; 

	public int moveSuccess;
	
	Environment map;
	AgentTable table;
	SystemDriver coordinate;
	
	public Agent( int ID, Environment map, SystemDriver coordinate, AgentTable table ) {
		
		this.side = Settings.side;
		this.cellCount = Settings.cellCount;
		this.map = map;
		this.coordinate = coordinate;
		this.table = table;
		
		moveSuccess = 0;
		
		// adding agent to agent table
		table.addAgent( this );
	}
	
	// method to queue next move with system driver
	public void moveForward( Move next ) {
		
		// if no new move object, return immediately
		if( next == null ) {
			
			return;
		}
		
		coordinate.queueMove( next );
		
		// busy-waiting while waiting for driver to return with results 
		while( moveSuccess == 0 ) {
			
			// perhaps add a communication function
		}
		
		// when results are positive, update current position within agent object
		if( moveSuccess == 1 ) {
			
			currentX = nextX;
			currentY = nextY;
		}
		
		moveSuccess = 0;
	}

	// method that runs within the thread
	public void run() {

	}
}
